<?php


require_once 'Operations/Operation.php';

/**
 * Makes Operation objects.
 * @author DePhille
 *
 */
class OperationFactory {
	/**
	 * Creates an operation from the given name.
	 * 
	 * @param operationName	Name of the operation to make.
	 * @return The corresponding operation.
	 */
	public function fromName($operationName) {
		
		// Check if operation is valid:
		if (!ctype_alnum($operationName)) {
			return null;
			
		// Check if file exists:
		} else if (!file_exists("Operations/" . $operationName . ".php")) {
			return null;
		}
		
		// Include file:
		require_once("Operations/" .$operationName . ".php");
		if (!class_exists($operationName)) {
			return null;
		}
		
		// Make and return operation:
		return new $operationName;
	}

}
?>
